# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     lexical_analyzer
   Description : 词法分析器
   Author :       Flyoung
   date：          2023/2/22
-------------------------------------------------
   Change Activity:
                   2023/2/22:
-------------------------------------------------
"""
from compiler.lexical.lexical_checker import LexicalChecker
from compiler.lexical.tokenizer import Tokenizer


class LexicalAnalyzer(object):
    def __init__(self, lines, log: bool = True):
        self.lines = lines
        # 词法检查器
        self.lc = LexicalChecker()
        # 分词器
        self.t = Tokenizer()
        self.log = log

    def check(self):
        """
        词法检查
        :return:
        """
        self.lc.check_variable_naming(self.lines, self.log)
        self.lc.check_bracket_match(self.lines, self.log)
        self.lc.check_constant_value(self.lines, self.log)

    def get_participle_result(self):
        """
        获取分解结果
        :return:
        """
        return self.t.parse_lines(self.lines)

    def show_participle_result(self):
        """
        展示分词结果
        :return:
        """
        self.t.parse_result(self.t.parse_lines(self.lines))
